import * as Router from 'koa-router';
import {koaBody} from 'koa-body'
import { DataExporter } from '../module/exportData';
import { UserModule } from '../module/user';
import { ChapterModule } from '../module/chapter';
//用来签名的密钥

const router = new Router();

router.prefix('/api')

router.post("/login",koaBody(), async ctx => {
  const { body } = ctx.request as any;
  //导出全表
  let result = await UserModule.ins.loginByName(body);
  ctx.body = {
    ret:0,
    data:result
  };
});

router.post("/loginWithPassword",koaBody(), async ctx => {
  const { body } = ctx.request as any;
  //导出全表
  let result = await UserModule.ins.loginWithPassword(body);
  ctx.body = {
    ret:0,
    data:result
  };
});

router.post("/register", koaBody(), async ctx => {
  const { body } = ctx.request as any;
  // 调用用户模块进行注册
  let result = await UserModule.ins.register(body);
  ctx.body = {
    ret: 0,
    data: result
  };
});

router.post("/forgot-password", koaBody(), async ctx => {
  const { body } = ctx.request as any;
  // 调用用户模块进行密码重置
  let result = await UserModule.ins.forgotPassword(body);
  ctx.body = {
    ret: 0,
    data: result
  };
});


export default router
